home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / dev / mui / MCC_SpeedBar.lha / MCC_SpeedBar / Developer / C / Examples / demo2.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-06  |  7.6 KB  |  201 lines

  1.  
  2. #include <proto/exec.h>
  3. #include <proto/dos.h>
  4. #include <proto/datatypes.h>
  5. #include <proto/muimaster.h>
  6. #include <clib/alib_protos.h>
  7. #include <mui/SpeedBar_mcc.h>
  8. #include <mui/SpeedBarCfg_mcc.h>
  9. #include <datatypes/pictureclass.h>
  10. #include <string.h>
  11. #include <stdio.h>
  12.  
  13. /***********************************************************************/
  14.  
  15. long __stack = 8192;
  16. struct Library *DataTypesBase;
  17. struct Library *MUIMasterBase;
  18.  
  19. /***********************************************************************/
  20.  
  21. #ifndef MAKE_ID
  22. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  23. #endif
  24.  
  25. /***********************************************************************/
  26.  
  27. struct MUIS_SpeedBar_Button buttons[] =
  28. {
  29.     {0, "_Get", "Get the disc.", 0, NULL},
  30.     {1, "Sa_ve", "Save the disc.", 0, NULL},
  31.     {2, "_Stop", "Stop the connection.", 0, NULL},
  32.     {MUIV_SpeedBar_Spacer},
  33.     {3, "_Disc", "Disc page.", 0, NULL},
  34.     {4, "_Matches", "Matches page.", 0, NULL},
  35.     {5, "_Edit", "Edit page.", 0, NULL},
  36.     {MUIV_SpeedBar_End},
  37. };
  38.  
  39. /***********************************************************************/
  40.  
  41. static Object *
  42. loadDTBrush(struct MyBrush *brush,STRPTR file)
  43. {
  44.     struct BitMapHeader *bmh;
  45.     register Object     *dto;
  46.  
  47.     if (!(dto = NewDTObject(file,DTA_GroupID,GID_PICTURE,PDTA_Remap,FALSE,PDTA_DestMode,PMODE_V42,TAG_DONE)) ||
  48.         !(DoMethod(dto,DTM_PROCLAYOUT,NULL,1)) ||
  49.         !(GetDTAttrs(dto,PDTA_DestBitMap,&brush->BitMap,PDTA_CRegs,&brush->Colors,PDTA_BitMapHeader,&bmh,TAG_DONE)==3))
  50.     {
  51.         if (dto)
  52.         {
  53.             DisposeDTObject(dto);
  54.             dto = NULL;
  55.         }
  56.         brush->BitMap = NULL;
  57.     }
  58.     else
  59.     {
  60.         brush->Width  = bmh->bmh_Width;
  61.         brush->Height = bmh->bmh_Height;
  62.     }
  63.  
  64.     return dto;
  65. }
  66.  
  67. /***********************************************************************/
  68.  
  69. #define TEMPLATE "STRIP,NUMBUTTON/N"
  70.  
  71. int
  72. main(int argc,char **argv)
  73. {
  74.     struct RDArgs   *ra;
  75.     LONG            arg[2] = {0};
  76.     int             res;
  77.  
  78.     if (ra = ReadArgs(TEMPLATE,arg,NULL))
  79.     {
  80.         if (DataTypesBase = OpenLibrary("datatypes.library",37))
  81.         {
  82.             if (MUIMasterBase = OpenLibrary("muimaster.library",19))
  83.             {
  84.                 struct MyBrush                  stripBrush;
  85.                 Object                          *dto, *app, *win, *sb;
  86.                 Object                          *cfg, *update;
  87.                 struct MUIS_SpeedBarCfg_Config  c = {MUIV_SpeedBar_ViewMode_TextGfx, MUIV_SpeedBarCfg_Borderless|MUIV_SpeedBarCfg_Sunny};
  88.  
  89.                 if (!(dto = loadDTBrush(&stripBrush,arg[0] ? (char *)arg[0] : "YAM:Icons/Main.toolbar")))
  90.                     printf("%s: warning can't load %s\n",argv[0],arg[0]);
  91.  
  92.                 if (app = ApplicationObject,
  93.                         MUIA_Application_Title,         "SpeedBar Demo2",
  94.                         MUIA_Application_Version,       "$VER: SpeedBarDemo2 (6.2.2002)",
  95.                         MUIA_Application_Copyright,     "Copyright 1999-2002 by Alfonso Ranieri",
  96.                         MUIA_Application_Author,        "Alfonso Ranieri <alforan@tin.it>",
  97.                         MUIA_Application_Description,   "Speed(Bar|Button|BarCfg).mcc test",
  98.                         MUIA_Application_Base,          "SPEEDBARTEST",
  99.                         SubWindow, win = WindowObject,
  100.                             MUIA_Window_ID,             MAKE_ID('M','A','I','N'),
  101.                             MUIA_Window_Title,          "SpeedBar Demo2",
  102.                             WindowContents, VGroup,
  103.                                 Child, HGroup,
  104.                                     GroupFrame,
  105.                                     Child, sb = SpeedBarObject,
  106.                                         MUIA_Group_Horiz,               TRUE,
  107.                                         MUIA_SpeedBar_Borderless,       TRUE,
  108.                                         MUIA_SpeedBar_Sunny,            TRUE,
  109.                                         MUIA_SpeedBar_Buttons,          buttons,
  110.                                         MUIA_SpeedBar_StripUnderscore,  TRUE,
  111.                                         MUIA_SpeedBar_EnableUnderscore, TRUE,
  112.                                         MUIA_SpeedBar_BarSpacer,        TRUE,
  113.                                         MUIA_SpeedBar_StripBrush,       &stripBrush,
  114.                                         MUIA_SpeedBar_StripButtons,     arg[1] ? (*((ULONG *)arg[1])) : 14,
  115.                                     End,
  116.                                     Child, HSpace(0),
  117.                                 End,
  118.                                 Child, VSpace(0),
  119.                                 Child, VGroup,
  120.                                     GroupFrameT("Appareance"),
  121.                                     Child, cfg = SpeedBarCfgObject,
  122.                                         MUIA_SpeedBarCfg_Config, &c,
  123.                                     End,
  124.                                     Child, VSpace(0),
  125.                                     Child, update = MUI_MakeObject(MUIO_Button,"_Update"),
  126.                                 End,
  127.                                 Child, VSpace(0),
  128.                             End,
  129.                         End,
  130.                     End)
  131.                 {
  132.                     ULONG sigs = 0, id;
  133.  
  134.                     DoMethod(win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,MUIV_Notify_Application,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  135.                     DoMethod(update,MUIM_Notify,MUIA_Pressed,FALSE,app,2,MUIM_Application_ReturnID,TAG_USER);
  136.  
  137.                     set(win,MUIA_Window_Open,TRUE);
  138.  
  139.                     while ((id = DoMethod(app,MUIM_Application_NewInput,&sigs))!=MUIV_Application_ReturnID_Quit)
  140.                     {
  141.                         if (id==TAG_USER)
  142.                         {
  143.                             struct MUIS_SpeedBarCfg_Config *c;
  144.  
  145.                             get(cfg,MUIA_SpeedBarCfg_Config,&c);
  146.  
  147.                             SetAttrs(sb,MUIA_SpeedBar_ViewMode,c->ViewMode,
  148.                                         MUIA_SpeedBar_Borderless,c->Flags & MUIV_SpeedBarCfg_Borderless,
  149.                                         MUIA_SpeedBar_RaisingFrame,c->Flags & MUIV_SpeedBarCfg_Raising,
  150.                                         MUIA_SpeedBar_SmallImages,c->Flags & MUIV_SpeedBarCfg_SmallButtons,
  151.                                         MUIA_SpeedBar_Sunny,c->Flags & MUIV_SpeedBarCfg_Sunny,
  152.                                         TAG_DONE);
  153.                         }
  154.  
  155.                         if (sigs)
  156.                         {
  157.                             sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  158.                             if (sigs & SIGBREAKF_CTRL_C) break;
  159.                         }
  160.                     }
  161.  
  162.                     MUI_DisposeObject(app);
  163.  
  164.                     res = RETURN_OK;
  165.                 }
  166.                 else
  167.                 {
  168.                     printf("%s: can't create application\n",argv[0]);
  169.                     res = RETURN_FAIL;
  170.                 }
  171.  
  172.                 if (dto) DisposeDTObject(dto);
  173.                 CloseLibrary(MUIMasterBase);
  174.             }
  175.             else
  176.             {
  177.                 printf("%s: Can't open muimaster.library ver 19 or higher\n",argv[0]);
  178.                 res = RETURN_ERROR;
  179.             }
  180.  
  181.             CloseLibrary(DataTypesBase);
  182.         }
  183.         else
  184.         {
  185.             printf("%s: can't open dtatypes.library ver 37 or higher\n",argv[0]);
  186.             res = RETURN_ERROR;
  187.         }
  188.  
  189.         FreeArgs(ra);
  190.     }
  191.     else
  192.     {
  193.         PrintFault(IoErr(),argv[0]);
  194.         return RETURN_FAIL;
  195.     }
  196.  
  197.     return res;
  198. }
  199.  
  200. /***********************************************************************/
  201.